var ejs = require('ejs');
var fs = require("fs") ;
var path = require('path');

module.exports = function(app){
	app.use("/demo", app.static(path.join(__dirname, '../public')));
	app.use("/demo/main.html", function(req, res){
		 fs.readFile(path.join(__dirname, '../public/main.ejs'),"utf8",function (error,data){
		    if(error) throw error ;
		    var postData = "";  
		    req.setEncoding("utf8");  
	        req.addListener("data",function(data){  
	            postData  += data;  
	        });  
	        req.addListener("end",function(){ 
	        	var renderd = ejs.render(data, JSON.parse(postData), {delimiter: '?'});
	        	res.writeHead(200, {
				     'Content-Type': 'text/html' 
				});
	            res.end(renderd);
	        })  
		     
		 });
	});
}